package walker

import (
	"bufio"
	"errors"
	"io"
	"os"
	"strings"
)

func GetFirstNotEmptyLine(path string) (string, error) {

	f, err := os.Open(path)
	if err != nil {
		return "", err
	}
	r := bufio.NewReader(f)
	for {
		s, err := r.ReadString('\n')
		if err == nil {
			s = strings.Trim(s, " \n")
			if strings.HasPrefix(s, "#") {
				continue
			}
			return s, nil
		} else if err == io.EOF {
			s = strings.Trim(s, " ")
			if strings.HasPrefix(s, "#") {
				return "", errors.New("not found")
			}
			return s, nil
		} else {
			return "", err
		}
	}

}
